unit clsNovinLock64;

interface
{

NOTES
  - NovinHIDLock.dll must be locate in Application Path or your windows SYSTEM32 folder
  + ErrNo return last used method error number :
    - 0 : Succeed
    - 1 : Device Not Found
    - you can get error description using ErrDescr proprty
  + Strings:
    - DNstring: is a string that it's character ASCIIs is seperated with '.'
    - string: 01234    ====> DN string :   48.49.50.52
    - sPWD: Password (DN string)
    - sVID: VID (DN string)

}

type
  TclsHIDLock = class

    procedure Init; stdcall ;
    procedure SelectDevice(Serial: WideString); stdcall ;
    procedure GetFirstDevice; stdcall ;
    procedure GetNextDevice; stdcall ;
    function GetDeviceCount:Word; stdcall ;
    function ConvStringToDelimiteredString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;
    function ConvDelimiteredStringToString(const strDCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;
    function ConvHexStringToDelimiteredString(strHCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;
    function ConvDelimiteredStringToHexString(const strDCnv: WideString;const ALen: Word=16;const DSep: WideString='.';const HSep: WideString=' '): WideString; stdcall ;
    function ConvStringToHEXString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString=' '): WideString; stdcall ;
    function ConvHEXStringToString(strHCnv: WideString;const ALen: Word=16): WideString; stdcall ;
    procedure GetDeviceReady; stdcall ;
    procedure GetDeviceStatus;stdcall ;
    function GetSerial: WideString; stdcall ;
    function GetVersion: WideString; stdcall ;
    function GetMemorySize: Word; stdcall ;
    function GetMemorySizeEx: WideString; stdcall ;
    function GetNET: Word; stdcall ;
    function GetPid(const sVID: WideString; const sPWD: WideString): WideString; stdcall ;
    function GetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString; stdcall ;
    procedure SetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataBlockStr: WideString;const defChar: WideString=chr(32)); stdcall ;
    function GetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString;stdcall ;
    procedure SetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataHexBlock: WideString);stdcall ;
    function GetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word): Byte; stdcall ;
    procedure SetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word;DataByte: Byte); stdcall ;
    function GetDataChar(sVID , sPWD:WideString; Index:word):WideString;stdcall ;
    procedure SetDataChar(sVID , sPWD:WideString; Index:word; DataChar:WideString);stdcall ;
    function GetDecryption(const sVID: WideString; const sPWD: WideString; const sCData: WideString;Repetition: Word): WideString; stdcall ;
    function GetEncryption(const sVID: WideString; const sPWD: WideString; const sPData: WideString;Repetition: Word): WideString; stdcall ;
    function GetTimerCounter: Integer;
    procedure DecreaseCounter;
    procedure Activate(const sActivationCode: WideString);stdcall ;

  protected

    function Get_ErrNo: Word; stdcall ;
    function Get_ErrDescr: WideString; stdcall ;
    function Get_ErrDescrFA: WideString; stdcall ;
    function Get_CurrDevName:widestring; stdcall ;
    function Get_CurrDevVer:widestring; stdcall ;
    function Get_CurrDevSerial:widestring; stdcall ;
    function Get_SelectedDevName:widestring; stdcall ;
    function Get_SelectedDevVer:widestring; stdcall ;
    function Get_SelectedDevSerial:widestring; stdcall ;

  public

    property ErrNo: Word read Get_ErrNo;
    property ErrDescr: WideString read Get_ErrDescr;
    property ErrDescrFA: WideString read Get_ErrDescrFA;
    property CurrDevName:widestring read Get_CurrDevName;
    property CurrDevVer:widestring read Get_CurrDevVer;
    property CurrDevSerial:widestring read Get_CurrDevSerial;
    property SelectedDevName:widestring read Get_SelectedDevName;
    property SelectedDevVer:widestring read Get_SelectedDevVer;
    property SelectedDevSerial:widestring read Get_SelectedDevSerial;

  end;


implementation

///////////////////////////////// Imports from dll ////////////////////////////////////

  procedure _Init; stdcall ;external 'LNovinHIDLock64.dll';
  procedure _SelectDevice(Serial: WideString); stdcall ;external 'LNovinHIDLock64.dll';
  procedure _GetFirstDevice; stdcall ;external 'LNovinHIDLock64.dll';
  procedure _GetNextDevice; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetDeviceCount:Word; stdcall ;external 'LNovinHIDLock64.dll';

  function _Get_ErrNo: Word; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_ErrDescr: WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_ErrDescrFA: WideString; stdcall ;external 'LNovinHIDLock64.dll';

  function _Get_CurrDevName:widestring; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_CurrDevVer:widestring; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_CurrDevSerial:widestring; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_SelectedDevName:widestring; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_SelectedDevVer:widestring; stdcall ;external 'LNovinHIDLock64.dll';
  function _Get_SelectedDevSerial:widestring; stdcall ;external 'LNovinHIDLock64.dll';

  function _ConvStringToDelimiteredString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _ConvDelimiteredStringToString(const strDCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;external 'LNovinHIDLock64.dll';

  function _ConvHexStringToDelimiteredString(strHCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _ConvDelimiteredStringToHexString(const strDCnv: WideString;const ALen: Word=16;const DSep: WideString='.';const HSep: WideString=' '): WideString; stdcall ;external 'LNovinHIDLock64.dll';

  function _ConvStringToHEXString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString=' '): WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _ConvHEXStringToString(strHCnv: WideString;const ALen: Word=16): WideString; stdcall ;external 'LNovinHIDLock64.dll';

  procedure _GetDeviceReady; stdcall ;external 'LNovinHIDLock64.dll';
  Procedure _GetDeviceStatus;stdcall ;external 'LNovinHIDLock64.dll';

  function _GetSerial: WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetVersion: WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetMemorySize: Word; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetMemorySizeEx: WideString; stdcall ;external 'LNovinHIDLock64.dll';

  function _GetNET: Word; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetPid(const sVID: WideString; const sPWD: WideString): WideString; stdcall ;external 'LNovinHIDLock64.dll';

  function _GetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString; stdcall ;external 'LNovinHIDLock64.dll';
  procedure _SetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataBlockStr: WideString;const defChar: WideString=chr(32)); stdcall ;external 'LNovinHIDLock64.dll';
  function _GetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString;stdcall ;external 'LNovinHIDLock64.dll';
  procedure _SetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataHexBlock: WideString);stdcall ;external 'LNovinHIDLock64.dll';
  function _GetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word): Byte; stdcall ;external 'LNovinHIDLock64.dll';
  procedure _SetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word;DataByte: Byte); stdcall ;external 'LNovinHIDLock64.dll';
  Function _GetDataChar(sVID , sPWD:WideString; Index:word):WideString;stdcall ;external 'LNovinHIDLock64.dll';
  procedure _SetDataChar(sVID , sPWD:WideString; Index:word; DataChar:WideString);stdcall ;external 'LNovinHIDLock64.dll';
  function _GetDecryption(const sVID: WideString; const sPWD: WideString; const sCData: WideString;Repetition: Word): WideString; stdcall ;external 'LNovinHIDLock64.dll';
  function _GetEncryption(const sVID: WideString; const sPWD: WideString; const sPData: WideString;Repetition: Word): WideString; stdcall ;external 'LNovinHIDLock64.dll';

  Function _GetTimerCounter: Integer;stdcall ;external 'LNovinHIDLock64.dll';
  Procedure _DecreaseCounter;stdcall ;external 'LNovinHIDLock64.dll';
  Procedure _Activate(const sActivationCode: WideString);stdcall ;external 'LNovinHIDLock64.dll';
//***************************************************************************************

///////////////////////////////////////////////////////////////////////////////////////

procedure TclsHIDLock.SelectDevice(Serial: WideString); 
begin
  _SelectDevice(Serial);
end;

procedure TclsHIDLock.GetFirstDevice; 
begin
  _GetFirstDevice;
end;

procedure TclsHIDLock.GetNextDevice;
begin
  _GetNextDevice;
end;

function TclsHIDLock.GetDeviceCount:Word;
begin
  Result:= _GetDeviceCount;
end;

function TclsHIDLock.ConvStringToDelimiteredString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString;
begin
  Result:= _ConvStringToDelimiteredString(strCnv,ALen,Sep);
end;

function TclsHIDLock.ConvDelimiteredStringToString(const strDCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString;
begin
  Result:= _ConvDelimiteredStringToString(strDCnv,ALen,Sep);
end;

function TclsHIDLock.ConvHexStringToDelimiteredString(strHCnv: WideString;const ALen: Word=16;const Sep: WideString='.'): WideString;
begin
  Result:= _ConvHexStringToDelimiteredString(strHCnv,ALen,Sep);
end;

function TclsHIDLock.ConvDelimiteredStringToHexString(const strDCnv: WideString;const ALen: Word=16;const DSep: WideString='.';const HSep: WideString=' '): WideString;
begin
  Result:= _ConvDelimiteredStringToHexString(strDCnv,ALen,DSep,HSep);
end;

function TclsHIDLock.ConvStringToHEXString(const strCnv: WideString;const ALen: Word=16;const Sep: WideString=' '): WideString;
begin
  Result:= _ConvStringToHEXString(strCnv,ALen,Sep);
end;

function TclsHIDLock.ConvHEXStringToString(strHCnv: WideString;const ALen: Word=16): WideString; 
begin
  Result:= _ConvHEXStringToString(strHCnv,ALen);
end;

procedure TclsHIDLock.GetDeviceReady;
begin
  _GetDeviceReady;
end;

procedure TclsHIDLock.GetDeviceStatus;
begin
  _GetDeviceStatus;
end;

function TclsHIDLock.GetSerial: WideString;
begin
  Result:= _GetSerial;
end;

function TclsHIDLock.GetVersion: WideString;
begin
  Result:= _GetVersion;
end;

function TclsHIDLock.GetMemorySize: Word;
begin
  Result:= _GetMemorySize;
end;

function TclsHIDLock.GetMemorySizeEx: WideString;
begin
  Result:= _GetMemorySizeEx;
end;

function TclsHIDLock.GetNET: Word;
begin
  Result:= _GetNET;
end;

function TclsHIDLock.GetPid(const sVID: WideString; const sPWD: WideString): WideString;
begin
  Result:= _GetPid(sVID,sPWD);
end;

function TclsHIDLock.GetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString;
begin
  Result:= _GetDataBlockStr(sVID,sPWD,Start,DataLen);
end;

procedure TclsHIDLock.SetDataBlockStr(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataBlockStr: WideString;const defChar: WideString=chr(32));
begin
  _SetDataBlockStr(sVID,sPWD,Start,DataLen,DataBlockStr,defChar);
end;

function TclsHIDLock.GetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word): WideString;
begin
  Result:= _GetDataHexBlock(sVID,sPWD,Start,DataLen)
end;

procedure TclsHIDLock.SetDataHexBlock(const sVID: WideString; const sPWD: WideString; Start: Word;DataLen: Word; const DataHexBlock: WideString);
begin
  _SetDataHexBlock(sVID,sPWD,Start,DataLen,DataHexBlock);
end;

function TclsHIDLock.GetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word): Byte; 
begin
  Result:= _GetDataByte(sVID,sPWD,Address);
end;

procedure TclsHIDLock.SetDataByte(const sVID: WideString; const sPWD: WideString; Address: Word;DataByte: Byte);
begin
  _SetDataByte(sVID,sPWD,Address,DataByte);
end;

function TclsHIDLock.GetDataChar(sVID , sPWD:WideString; Index:word):WideString;
begin
  Result:= _GetDataChar(sVID, sPWD, Index);
end;

procedure TclsHIDLock.SetDataChar(sVID , sPWD:WideString; Index:word; DataChar:WideString);
begin
  _SetDataChar(sVID , sPWD, Index, DataChar);
end;

function TclsHIDLock.GetDecryption(const sVID: WideString; const sPWD: WideString; const sCData: WideString;Repetition: Word): WideString;
begin
  Result:= _GetDecryption(sVID, sPWD, sCData, Repetition);
end;

function TclsHIDLock.GetEncryption(const sVID: WideString; const sPWD: WideString; const sPData: WideString;Repetition: Word): WideString;
begin
  Result:= _GetEncryption(sVID,sPWD,sPData,Repetition);
end;

function TclsHIDLock.GetTimerCounter: Integer;
begin
  Result:= _GetTimerCounter;
end;

procedure TclsHIDLock.DecreaseCounter;
begin
  _DecreaseCounter;
end;

procedure TclsHIDLock.Activate(const sActivationCode: WideString);
begin
  _Activate(sActivationCode);
end;

function TclsHIDLock.Get_ErrNo: Word;
begin
  Result:= _Get_ErrNo;
end;

function TclsHIDLock.Get_ErrDescr: WideString;
begin
  Result:= _Get_ErrDescr;
end;

function TclsHIDLock.Get_ErrDescrFA: WideString;
begin
  Result:= _Get_ErrDescrFA;
end;

function TclsHIDLock.Get_CurrDevName:widestring;
begin
  Result:= _Get_CurrDevName;
end;

function TclsHIDLock.Get_CurrDevVer:widestring;
begin
  Result:= _Get_CurrDevVer;
end;

function TclsHIDLock.Get_CurrDevSerial:widestring;
begin
  Result:= _Get_CurrDevSerial;
end;

function TclsHIDLock.Get_SelectedDevName:widestring;
begin
  Result:= _Get_SelectedDevName;
end;

function TclsHIDLock.Get_SelectedDevVer:widestring;
begin
  Result:= _Get_SelectedDevVer;
end;

function TclsHIDLock.Get_SelectedDevSerial:widestring;
begin
  Result:= _Get_SelectedDevSerial;
end;

procedure TclsHIDLock.Init; stdcall;
begin
  _Init;
end;


end.
